import type { PostPatientConsultOrderParams } from '@/types/consult'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export type ConsultIllnessInfo = Pick<
  PostPatientConsultOrderParams,
  'illnessDesc' | 'illnessTime' | 'consultFlag' | 'pictures'
>

export const useConsultStore = defineStore(
  'consult',
  () => {
    // 初始化订单信息

    const initValue: ConsultIllnessInfo = {
      illnessDesc: '',
      illnessTime: 1,
      consultFlag: 0,
      pictures: [],
    }
    const illnessInfo = ref<ConsultIllnessInfo>(initValue)

    // 地址栏的信息
    const query = ref({
      type: '',
      illnessType: '',
      depId: '',
    })

    // 患者信息
    const patientID = ref('')

    // 清空订单信息
    const clearOrder = () => {
      illnessInfo.value = { ...initValue }
      query.value = {
        type: '',
        illnessType: '',
        depId: '',
      }
      patientID.value = ''
    }
    return { illnessInfo, query, patientID, clearOrder }
  },
  { persist: true }
)
